JBoss Community Archive (Read Only)

Infinispan 5.1

Cassandra CacheStore

Infinispan's CassandraCacheStore leverages Apache Cassandra's distributed database architecture to provide a virtually unlimited, horizontally scalable persistent store for Infinispan's caches.

Version

The Cassandra CacheStore was added in Infinspan 4.2.0 "Ursus". You'll need this release or later in order to use it.

Configuration

In order to use this CacheStore you need to create an appropriate  keyspace on your Cassandra database. The following storage-conf.xml  excerpt shows the declaration of the keyspace:

{code:xml}<Keyspace Name="Infinispan">
<ColumnFamily CompareWith="BytesType" Name="InfinispanEntries" KeysCached="10%" />
      <ColumnFamily CompareWith="LongType" Name="InfinispanExpiration" KeysCached="10%" ColumnType="Super" CompareSubcolumnsWith="BytesType"/>
      <ColumnFamily CompareWith="BytesType" Name="InfinispanEntries" KeysCached="0" />
      <ColumnFamily CompareWith="LongType" Name="InfinispanExpiration" KeysCached="0" ColumnType="Super" CompareSubcolumnsWith="BytesType"/>
      <ReplicaPlacementStrategy>org.apache.cassandra.locator.RackUnawareStrategy</ReplicaPlacementStrategy>
      <ReplicationFactor>2</ReplicationFactor>
      <EndPointSnitch>org.apache.cassandra.locator.EndPointSnitch</EndPointSnitch>

</Keyspace>

<p></p><p>The important bits are the CompareWith, ColumnType and CompareSubColumnsWith declarations. Everything else can be changed at will. You can also have more than one Keyspace to accomodate for multiple caches.</p><p></p><p>You then need to add an appropriate cache declaration to your infinispan.xml (or whichever file you use to configure Infinispan):</p><p></p><p></p>
<namedCache name="cassandraCache">
        <loaders passivation="false" shared="true" preload="false">
                <loader
                        class="org.infinispan.loaders.cassandra.CassandraCacheStore"
                        fetchPersistentState="true" ignoreModifications="false"
                        purgeOnStartup="false">
                        <properties>
                                <property name="host" value="localhost" />
                                <property name="keySpace" value="Infinispan" />
                                <property name="entryColumnFamily" value="InfinispanEntries" />
                                <property name="expirationColumnFamily" value="InfinispanExpiration" />
                                <property name="sharedKeyspace" value="false" />
                                <property name="readConsistencyLevel" value="ONE" />
                                <property name="writeConsistencyLevel" value="ONE" />
                                <property name="configurationPropertiesFile" value="cassandrapool.properties" />          
                                <property name="keyMapper" value="org.infinispan.loaders.keymappers.DefaultTwoWayKey2StringMapper" />


                        </properties>



                </loader>



        </loaders>



</namedCache>
<p></p><p></p><p>It is important the the shared property on the loader element is set to true because all the Infinispan nodes will share the same Cassandra cluster.</p><p></p><p>Since the Cassandra client library doesn't provide connection pooling, a separate project has been created at <a class="active_link" href="http://github.com/tristantarrant/cassandra-connection-pool">http://github.com/tristantarrant/cassandra-connection-pool</a></p><p></p><p>Configuration of the connection pool can be done by creating an appropriate properties file and specifying its name in the configuration (<strong>configurationPropertiesFile</strong>).</p><p></p><p>The following is an example file:</p><p></p><p></p>
socketTimeout = 5000
initialSize = 10
maxActive = 100
maxIdle = 20
minIdle = 10
maxWait = 30000testOnBorrow = false
testOnReturn = false
testWhileIdle = false
timeBetweenEvictionRunsMillis = 5000removeAbandoned = false
removeAbandonedTimeout = 60
logAbandoned = false
{code}
Here is a description of the various properties which can be configured:
Header 1 Header 2

host

a hostname (or a comma-separated list of hostnames)

port

the thrift port (usually 9160)

keySpace

the keyspace to use (defaults to Infinispan)

entryColumnFamily

the column family where entry values will be stored. Make sure you configure your keyspace accordingly (defaults to InfinispanEntries)

expirationColumnFamily

the column family where element expiration information is stored. Make sure your  (defaults to InfinispanExpiration)

sharedKeyspace

whether multiple caches are to be stored in a single keyspace. In this case the cache name is prefixed to the key entries (defaults to false).

readConsistencyLevel

The consistency level to use when reading from Cassandra. Possible values are ONE, QUORUM, DCQUORUM, ALL. For an explanation of these refer to the Cassandra API documentation. (defaults to ONE)

writeConsistencyLevel

The consistency level to use when writing to Cassandra. Possible values are ZERO, ANY, ONE, QUORUM, DCQUORUM, ALL. For an explanation of these refer to the Cassandra API documentation. (defaults to ONE)

keyMapper

A class which implements Infinispan's TwoWayKey2StringMapper interface for mapping cache keys to Cassandra row keys (defaults to org.infinispan.loaders.keymappers.DefaultTwoWayKey2StringMapper)

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-11 09:16:44 UTC, last content change 2010-12-03 16:44:14 UTC.